package com.example.sy3;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ResultServlet
 */

@WebServlet(name = "ResultServlet", value = "/ResultServlet")
public class ResultServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("username");// 获取用户姓名
        String pwd =  request.getParameter("password")                  ;// 获取用户密码
        String age =  request.getParameter("age")                 ;// 获取用户年龄
        String sex =   request.getParameter("sex")                 ;// 获取用户性别
        String[] loves =  request.getParameterValues("loves")                   ;// 获取用户爱好
        String email =  request.getParameter("email")                   ;// 获取用户EAMIL
        String tel =  request.getParameter("tel")                  ;// 获取用户联系电话

        // 中文乱码处理，取决于你的tomcat版本，如果版本高于6.5是不需要的
//        name = new String(name.getBytes(), "UTF-8");
//        for (int i = 0; i <loves.length; i++)
//            loves[i] = new String(loves[i].getBytes(), "UTF-8");

        response.setContentType("text/html;charset=utf-8");


        PrintWriter pWriter = response.getWriter();
        pWriter.print("<body  bgcolor='pink'>");
        if (pwd.length() < 6 || pwd.length() > 10)
            pWriter.print("输入的密码不符合标椎<br/>");
        // 显示用户的注册信息
        pWriter.print("用户名: " + name + "<br/>");
        pWriter.print("密码:" +  pwd + "<br/>");
        pWriter.print("年龄:" + age + "<br/>");
        pWriter.print("性别:" + sex + "<br/>");
        pWriter.print("爱好: " + Arrays.toString(loves) + "<br/>");
        pWriter.print("Email:" + email + "<br/>");
        pWriter.print("Tel:" + tel + "<br/>");
        pWriter.print("</body>");
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}